Skip to content

fix(crypto): implement crypto primitives, hex wire format, and full test suite - #48

Merged
Just-Bamford merged 2 commits into
AnonVote:mainfrom
k-deejah:fix/issue-39-crypto-primitives
Jul 29, 2026
Merged

fix(crypto): implement crypto primitives, hex wire format, and full test suite#48
Just-Bamford merged 2 commits into
AnonVote:mainfrom
k-deejah:fix/issue-39-crypto-primitives

Conversation

@k-deejah

Copy link
Copy Markdown
Contributor

closes #39

  • Add DECISIONS.md documenting ADR-001: hex output format for encryptVote
  • Implement encryptVote returning EncryptedPayload object with hex-encoded ciphertext, iv, and authTag (fixes base64/hex mismatch with AnonVote/core)
  • Implement decryptVote accepting EncryptedPayload; auth tag failure throws AnonVoteCryptoError(DECRYPTION_FAILED) — never swallowed silently
  • Validate key as exactly 64 hex chars; throw AnonVoteCryptoError(INVALID_KEY) before any cipher op
  • Validate payload fields in decryptVote; throw INVALID_PAYLOAD if missing/empty
  • hashIdentifier: trim + lowercase normalisation enforced
  • generateToken: 32-byte CSPRNG, hex output, JSDoc @warning against reuse
  • hashToken: separate export from hashIdentifier for independent testability
  • Add EncryptedPayload, Token, Vote, ElectionResult, BallotEvent interfaces and AnonVoteCryptoError class to src/types.ts
  • Export all canonical types and AnonVoteCryptoError from src/index.ts
  • Rewrite tests/crypto.test.ts with all 25 cases per issue spec
  • Update src/client.ts and tests/client.test.ts to use new EncryptedPayload object (serialised as JSON string in VoteReceipt.encryptedPayload)
  • All 73 tests pass; clean tsc build with no errors

k-deejah and others added 2 commits July 29, 2026 03:22
…est suite (AnonVote#39)

- Add DECISIONS.md documenting ADR-001: hex output format for encryptVote
- Implement encryptVote returning EncryptedPayload object with hex-encoded
  ciphertext, iv, and authTag (fixes base64/hex mismatch with AnonVote/core)
- Implement decryptVote accepting EncryptedPayload; auth tag failure throws
  AnonVoteCryptoError(DECRYPTION_FAILED) — never swallowed silently
- Validate key as exactly 64 hex chars; throw AnonVoteCryptoError(INVALID_KEY)
  before any cipher op
- Validate payload fields in decryptVote; throw INVALID_PAYLOAD if missing/empty
- hashIdentifier: trim + lowercase normalisation enforced
- generateToken: 32-byte CSPRNG, hex output, JSDoc @warning against reuse
- hashToken: separate export from hashIdentifier for independent testability
- Add EncryptedPayload, Token, Vote, ElectionResult, BallotEvent interfaces
  and AnonVoteCryptoError class to src/types.ts
- Export all canonical types and AnonVoteCryptoError from src/index.ts
- Rewrite tests/crypto.test.ts with all 25 cases per issue spec
- Update src/client.ts and tests/client.test.ts to use new EncryptedPayload
  object (serialised as JSON string in VoteReceipt.encryptedPayload)
- All 73 tests pass; clean tsc build with no errors
@Just-Bamford
Just-Bamford merged commit 8c12080 into AnonVote:main Jul 29, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cryptographic primitives implementation

2 participants